function MainAssistant(argFromPusher) {
}

MainAssistant.prototype = {
	setup: function() {
		Ares.setupSceneAssistant(this);
		
		// Get the first 10 images when setting up the scene
		this.$.Flickr.execute();
	},
	
	activate: function() {
		// Disable rotation -- needs to be vertical to accurately represent wallpaper
		this.controller.stageController.setWindowOrientation( "up" );
		
		// Show the button for 3 seconds, then hide; we'll show again when user taps the image
		this.displayButton();
	},
	
	deactivate: function() {
	// Re-enable free rotation
		this.controller.stageController.setWindowOrientation( "free" );
	},

	cleanup: function() {
		Ares.cleanupSceneAssistant(this);
	},

	FlickrSuccess: function(inSender, inResponse, inRequest) {
		var results = inResponse.query.results;
		var iV = this.$.imageView1;
		
		// Add the image URLs to the ImageView widget's "images" array
		for ( var i = 0; i < results.photo.length; i++ ) {
			var p = results.photo[ i ];
			iV.images.push(
				"http://farm" + p.farm + ".static.flickr.com/" +
				p.server + "/" + p.id + "_" + p.secret + ".jpg"
			);
		}
		
		// Use Mojo methods to set the current (center) and next (right) images
		// Ares should provide a setImages() method to do this, but doesn't yet
		iV.node.mojo.centerUrlProvided( iV.images[ iV.index ] );
		iV.node.mojo.rightUrlProvided( iV.images[ iV.index + 1 ] );
	},

	button1Tap: function(inSender, event) {
		var dl = this.$.download1;
		var iV = this.$.imageView1;
		
		// Store info about current image (url, zoom, focus) so that we can download it
		// and (once downloaded) apply the same zoom/focus when setting wallpaper
		this.imageParams = iV.node.mojo.getCurrentParams();
		
		// Initiate the download
		dl.setFileUrl( this.imageParams.sourceImage );
		dl.download();
	},
	
	download1Success: function(inSender, inResponse, inRequest) {
		// Ignore progress updates, set wallpaper when download is complete
		if ( inResponse.completed ) {
			// Cancel subscription to download status events so we can reuse the component later
			inSender.cancel();
			
			var wp = this.$.wallpaper1;
			wp.setImportUrl("file://" + inResponse.target);
			
			// Apply the zoom/focus we stored before downloading, set the wallpaper
			wp.setFocusX(this.imageParams.focusX);
			wp.setFocusY(this.imageParams.focusY);
			wp.setScale(this.imageParams.scale);
			wp.importWallpaper();
		}
	},

	// Display the button for 3 seconds when activating scene and after user taps image
	displayButton: function(inSender, event) {
		var button = this.$.button1;
		button.setShowing( true );
		setTimeout( function() {
			button.setShowing( false );
		}, 3000 );
	},

	// Get 10 more images from Flickr when user reaches the end of the current crop
	imageView1RightFunction: function(inSender) {
		var iV = this.$.imageView1;
		if( iV.index == iV.images.length - 1 ) {
			var F = this.$.Flickr;
			F.parameters.q = "select * from flickr.photos.interestingness(" + iV.images.length + ", 10)";
			F.execute();
		}
	}
};